﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Kinect;
using Microsoft.Win32;
using Kinect.Toolbox;
using Kinect.Toolbox.Gestures;
using Kinect.Toolbox.Voice;
using System.Threading;
using System.Threading.Tasks;
using Kinect.Toolbox.Record;
using Microsoft.Speech.AudioFormat;
using Microsoft.Speech.Recognition;
using Kinectver1._0.CadObject;
using Kinectver1._0.openScad;
using Kinectver1._0;

namespace Kinectver1._0
{
    class AudioClass
    {
        public AudioClass(KinectSensor thisSensor, InitGesture thisDetector)
        {
            sensor = thisSensor;
        //    sensor = kaudio;
            InitGestureDetector = thisDetector;
            ontheflylocal = false;
            is_Creating = false;
            is_Editing = false;
            is_Rotating = false;
            is_Scaling = false;
            is_Translating = false;
            is_Cube = false;
            is_Circle = false;
            is_Cube = false;
            is_Square = false;
            is_Cylinder = false;
            is_Done = false;
            is_Gestures = false;
            is_Set = false;
            is_Bool = false;
            said_bool = false;
            is_intersection = false;
            is_union = false;
            is_difference = false;
            is_numb_edit = false;
            is_finished = false;
        }
        public cadObject selectedOne;
        public cadObject selectedTwo;
        string lastRecogShape;
        string lastRecogVoice;
        string audio_numb = "";

        public string stored_audio_number = "";
        public bool ontheflylocal { set; get; }
        public string audio_number = "";
        //KinectAudioSource sensor;
        KinectSensor sensor;
        InitGesture InitGestureDetector;
        //ui stuff
        List<string> startingCommands = new List<string>();
        List<string> IntializeList = new List<string>();
        List<string> CreateList = new List<string>();
        List<string> NumberList = new List<string>();
        List<string> EditList = new List<string>();
        List<string> MergeList = new List<string>();
        List<string> SceneList = new List<string>();
        List<string> ShapeList = new List<string>();
        List<string> SetList = new List<string>();
        List<string> param1Commands = new List<string>(); //this can change if you need to
        ComboBox command;
        ComboBox param1;
        ComboBox param2;
        ComboBox param3;
        ComboBox number;
        public CoordinatePlane Coordpl { set; get;}
        TextBox numberbox;
        public objectManager objManAud;
        public ListView AudObjectViewer;
        public TextBox Audshapex;
        public TextBox Audshapey;
        public TextBox Audshapez;
        public bool is_Rotating { set; get; }
        public bool is_Scaling { set; get; }
        public bool is_Translating { set; get; }
        public bool is_intersection { get; set; }
        public bool is_union { get; set; }
        public bool is_difference { get; set; }
        public bool is_Creating { set; get; }
        public bool is_Editing { set; get; }
        public bool is_Square { set; get; }
        public bool is_Cube { set; get; }
        public bool is_Circle { set; get; }
        public bool is_Sphere { get; set; }
        public bool is_Cylinder { get; set; }
        public bool is_Done { get; set; }
        public bool is_set_cancel { get; set; }
        public bool is_Gestures { set; get; }
        public bool is_Set { get; set; }
        public bool is_Select { get; set; }
        public bool is_edit_Select { get; set; }
        public bool is_Bool { get; set; }
        public bool said_bool { get; set; }
        public bool is_numb_edit { get; set; }//= false;
        public bool is_finished { get; set; }

        public Choices cmdchoices = new Choices();
        public Choices createchoices = new Choices();
        public Choices editchoices = new Choices();
        public Choices mergechoices = new Choices();
        public Choices scenechoices = new Choices();
        public Choices numbchoices = new Choices();
        public Choices shapechoices = new Choices();
        public Choices setChoice = new Choices();

        public GrammarBuilder cmd { get; set; }
        public GrammarBuilder create { get; set; }
        public GrammarBuilder edit { get; set; }
        public GrammarBuilder merge { get; set; }
        public GrammarBuilder scene { get; set; }
        public GrammarBuilder numbers { get; set; }
        public GrammarBuilder shape { get; set; }
        public GrammarBuilder set { get; set; }

        public Grammar gcmd { get; set; }

        public Grammar gcreate { get; set; }
        public Grammar gedit { get; set; }
        public Grammar gmerge { get; set; }
        public Grammar gscene { get; set; }
        public Grammar gshape { get; set; }
        public Grammar gnumber { get; set; }
        public Grammar gset { get; set; }
        //and the speech recognition engine (SRE)
        public SpeechRecognitionEngine speechRecognizer;
        //Get the speech recognizer (SR)
        //MainWindow mainwindowref = new MainWindow();
        private static RecognizerInfo GetKinectRecognizer()
        {
            Func<RecognizerInfo, bool> matchingFunc = r =>
            {
                string value;
                r.AdditionalInfo.TryGetValue("Kinect", out value);
                return "True".Equals(value, StringComparison.InvariantCultureIgnoreCase) && "en-US".Equals(r.Culture.Name, StringComparison.InvariantCultureIgnoreCase);
            };
            return SpeechRecognitionEngine.InstalledRecognizers().Where(matchingFunc).FirstOrDefault();
        }

        public void linkObj(objectManager obj)
        {
            objManAud = obj;
        }

        public void linkCoord_plane(CoordinatePlane coord)
        {
            Coordpl = coord;
        }

        public void link_list_view(ListView LW)
        {
            AudObjectViewer = LW;
        }


        public void loadInitialMenu(ComboBox cmd, ComboBox p1, ComboBox p2, ComboBox p3, ComboBox Num, TextBox Numbox)
        {
            this.command = cmd;
            this.param1 = p1;
            this.param2 = p2;
            this.param3 = p3;
            this.number = Num;
            this.numberbox = Numbox;

            //load up command for example

            startingCommands.Add("CREATE");
            startingCommands.Add("EDIT");
            startingCommands.Add("MERGE");
            startingCommands.Add("SCENE");

            NumberList.Add("ZERO");
            NumberList.Add("ONE");
            NumberList.Add("TWO");
            NumberList.Add("THREE");
            NumberList.Add("FOUR");
            NumberList.Add("FIVE");
            NumberList.Add("SIX");
            NumberList.Add("SEVEN");
            NumberList.Add("EIGHT");
            NumberList.Add("NINE");
            NumberList.Add("POINT");
            NumberList.Add("DONE");
            NumberList.Add("SET");
            NumberList.Add("FINISHED");
            NumberList.Add("CANCEL");


            CreateList.Add("CIRCLE");       
            CreateList.Add("SQUARE");
            CreateList.Add("POLYGON");
            CreateList.Add("SPHERE");
            CreateList.Add("CUBE");
            CreateList.Add("CYLINDER");
            CreateList.Add("POLYHEDRON");
            CreateList.Add("CANCEL");
            CreateList.Add("BOOL");

            EditList.Add("TRANSLATE");
            EditList.Add("ROTATE");
            EditList.Add("SCALE");
 //           EditList.Add("RESIZE");
 //           EditList.Add("MIRROR");
            EditList.Add("MULTMATRIX");
            EditList.Add("COLOR");
            EditList.Add("HULL");
            EditList.Add("CANCEL");

            MergeList.Add("UNION");
            MergeList.Add("DIFFERENCE");
            MergeList.Add("INTERSECTION");
            MergeList.Add("CANCEL");

            SceneList.Add("UP");
            SceneList.Add("DOWN");
            SceneList.Add("LEFT");
            SceneList.Add("RIGHT");
            SceneList.Add("FORWARD");
            SceneList.Add("BACK");
            SceneList.Add("CLOCKWISE");
            SceneList.Add("COUNTER");
            SceneList.Add("SET");
            SceneList.Add("CANCEL");

            ShapeList.Add("EXACT");
            ShapeList.Add("GESTURE");
            ShapeList.Add("CHOOSE");
            ShapeList.Add("CANCEL");

            SetList.Add("SET");
            SetList.Add("CHOOSE");
            SetList.Add("DONE");
            SetList.Add("CANCEL");

            cmd.ItemsSource = startingCommands;
            cmd.IsDropDownOpen = true;
            cmd.SelectedIndex = 0; //show commands
            //lets disable the other menues for now
            param1.IsEnabled = false;
            param2.IsEnabled = false;
            param3.IsEnabled = false;
            number.IsEnabled = false;
        }
        

        //Start streaming audio
        public void Start()
        {
            //set sensor audio source to variable
            var audioSource = sensor.AudioSource;
            //Set the beam angle mode - the direction the audio beam is pointing
            //we want it to be set to adaptive
            //this.speechRecognizer = this.CreateSpeechRecognizer();
            audioSource.BeamAngleMode = BeamAngleMode.Adaptive;
            //lastRecogVoice = DateTime.Now;
            //start the audiosource 
            var kinectStream = audioSource.Start();
            //configure incoming audio stream
            speechRecognizer.SetInputToAudioStream(
            kinectStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            //make sure the recognizer does not stop after completing     
            speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
            //reduce background and ambient noise for better accuracy
            sensor.AudioSource.EchoCancellationMode = EchoCancellationMode.None;
            sensor.AudioSource.AutomaticGainControlEnabled = false;

        }

        /*Initilaize the kinect
        private KinectSensor InitializeKinect()
        {
            //get the first available sensor and set it to the current sensor variable
            CurrentSensor = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected);  
            // was indented before ".firstOrDefault

            speechRecognizer = CreateSpeechRecognizer();
            //Start the sensor
            CurrentSensor.Start();
            //then run the start method to start streaming audio
            Start();
            return CurrentSensor;
        } */
        // audio code
        //create the speech recognizer
        public SpeechRecognitionEngine CreateSpeechRecognizer()
        {
            //set recognizer info
            RecognizerInfo ri = GetKinectRecognizer();
            //create instance of SRE
            SpeechRecognitionEngine sre;
            sre = new SpeechRecognitionEngine(ri.Id);


            //add the words we want our program to recognize, very simple 
            numbchoices.Add("zero");
            numbchoices.Add("one");
            numbchoices.Add("two");
            numbchoices.Add("three");
            numbchoices.Add("four");
            numbchoices.Add("five");
            numbchoices.Add("six");
            numbchoices.Add("seven");
            numbchoices.Add("eight");
            numbchoices.Add("nine");
            numbchoices.Add("point");
            numbchoices.Add("help");
            numbchoices.Add("Cancel");
            numbchoices.Add("Done");
            numbchoices.Add("Set");
            numbchoices.Add("Finished");

            createchoices.Add("circle");
            createchoices.Add("square");
            createchoices.Add("polygon");
            createchoices.Add("sphere");
            createchoices.Add("cube");
            createchoices.Add("cylinder");
            createchoices.Add("polyhedron");
            createchoices.Add("help");
            createchoices.Add("Bool");
            createchoices.Add("Cancel");

            editchoices.Add("translate");
            editchoices.Add("choose");
            editchoices.Add("rotate");
            editchoices.Add("scale");
 //           editchoices.Add("resize");
//            editchoices.Add("mirror");
            editchoices.Add("multmatrix");
            editchoices.Add("color");
            editchoices.Add("hull");
            editchoices.Add("help");
            editchoices.Add("Cancel");


            mergechoices.Add("union");
            mergechoices.Add("difference");
            mergechoices.Add("intersection");
            mergechoices.Add("Help");
            mergechoices.Add("Cancel");

            setChoice.Add("set");
            setChoice.Add("Done");
            setChoice.Add("Help");
            setChoice.Add("Choose");
            setChoice.Add("Cancel");

            cmdchoices.Add("Create");
            cmdchoices.Add("Edit");
            cmdchoices.Add("Merge");
            cmdchoices.Add("Scene");
            cmdchoices.Add("Set");
            cmdchoices.Add("Help");
            cmdchoices.Add("Cancel");

            scenechoices.Add("left");
            scenechoices.Add("right");
            scenechoices.Add("up");
            scenechoices.Add("down");
            scenechoices.Add("forward");
            scenechoices.Add("back");
            scenechoices.Add("clockwise");
            scenechoices.Add("counter");
            scenechoices.Add("set");
            scenechoices.Add("cancel");
            scenechoices.Add("help");


            shapechoices.Add("Exact");
            shapechoices.Add("Gesture");
            shapechoices.Add("Help");
            shapechoices.Add("Choose");
            shapechoices.Add("Cancel");

            //set culture - language, country/region
            cmd = new GrammarBuilder { Culture = ri.Culture };
            create = new GrammarBuilder { Culture = ri.Culture };
            edit = new GrammarBuilder { Culture = ri.Culture };
            merge = new GrammarBuilder { Culture = ri.Culture };
            scene = new GrammarBuilder { Culture = ri.Culture };
            shape = new GrammarBuilder { Culture = ri.Culture };
            numbers = new GrammarBuilder { Culture = ri.Culture };
            set = new GrammarBuilder { Culture = ri.Culture };

            cmd.Append(cmdchoices);
            create.Append(createchoices);
            edit.Append(editchoices);
            merge.Append(mergechoices);
            scene.Append(scenechoices);
            shape.Append(shapechoices);
            numbers.Append(numbchoices);
            set.Append(setChoice);
            //gb.Append(cmdchoices);
            //ngb.Append(numb_gramm);
            //set up grammar builder
            gcmd = new Grammar(cmd);
            gcreate = new Grammar(create);
            gedit = new Grammar(edit);
            gmerge = new Grammar(merge);
            gscene = new Grammar(scene);
            gshape = new Grammar(shape);
            gnumber = new Grammar(numbers);
            gset = new Grammar(set);
            //var ng = new Grammar(ngb);

            sre.LoadGrammar(gcmd);
            //sre.LoadGrammar(ng);        //testing what loading two grammars will do


            //Set events for recognizing, hypothesising and rejecting speech
            sre.SpeechRecognized += SreSpeechRecognized;
            sre.SpeechHypothesized += SreSpeechHypothesized;
            sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected;
            return sre;
        }


        //if speech is rejected, this is the function we goto
        private void RejectSpeech(RecognitionResult result)
        {
            //mainwindowref.text1.Text = "What did you say?";
        }

        private void SreSpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            RejectSpeech(e.Result);
        }

        //hypothesized result, this is what the kinect thinks it hears, it could have a REALLY low
        //confidence though so the input isn't necessarily accepted
        private void SreSpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
        {
            //text1.Text = e.Result.Text + " " + e.Result.Confidence;
        }

        public bool get_fly()
        {
            return ontheflylocal;
        }

        public void writeToScad()
        {


            StreamWriter writer = new StreamWriter(@"C:\Program Files (x86)\openSCAD\projectOutput.scad");

            for (int i = 0; i < objManAud.Objects.Count; i++)
            {
                writer.Write(objManAud.Objects[i].toScad());
            }

            writer.Close();

            Console.Write("openscad -o " + @"C:\Program Files (x86)\OpenSCAD\cube2by2by2.off " + @"C:\Program Files (x86)\openSCAD\projectOutput.scad");
        }

        public void update_GUI_Shape(string shape)
        {
            if(shape == "circle")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 0;
            }
            else if (shape == "square")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 1;
            }
            else if (shape == "polygon")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 2;
            }
            else if (shape == "sphere")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 3;
            }
            else if (shape == "cube")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 4;
            }
            else if (shape == "cylinder")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 5;
            }
            else if (shape == "polyhedron")
            {
                param2.IsEnabled = true;
                param2.ItemsSource = ShapeList;
                this.param2.IsDropDownOpen = true;
                speechRecognizer.UnloadAllGrammars();
                speechRecognizer.LoadGrammar(gshape);
                this.param1.SelectedIndex = 6;
            }
        }

        public void testobjectpos(objectManager oman)
        {
            if (oman.Count > 0)
            {
                Audshapex.Text = ((float)oman.currentSelected.Origin.X).ToString();
                Audshapey.Text = ((float)oman.currentSelected.Origin.Y).ToString();
                Audshapez.Text = ((float)oman.currentSelected.Origin.Z).ToString();
            }
        }

        //Speech is recognised, if the kinect hears audio it will go here
        private void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Confidence < .65)   //the number in this line corresponds to the our confidence level check
            {
                RejectSpeech(e.Result);
                //text3.Text = " ";
            }
            //the SRE recognizes a word
            else
            {
                if (param1.IsDropDownOpen == true)
                    param1.IsDropDownOpen = false;
                if (param2.IsDropDownOpen == true)
                    param2.IsDropDownOpen = false;
                if (param3.IsDropDownOpen == true)
                    param3.IsDropDownOpen = false;
                if (number.IsDropDownOpen == true)
                    number.IsDropDownOpen = false;

                //this switch statement is the loop in which we decide which grammar to use
                switch (e.Result.Text.ToUpperInvariant())
                {
                    case "CREATE":
                        is_Creating = true;
                        this.command.IsDropDownOpen = false;
                        this.command.SelectedIndex = 0;
                        lastRecogVoice = "create";
                        param1.IsEnabled = true;
                        param1.ItemsSource = CreateList;
                        this.param1.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcmd);
                        speechRecognizer.LoadGrammar(gcreate);
                        break;
                    case "EDIT":
                        if (objManAud.Count != 0)
                        {
                            is_Editing = true;
                            this.command.IsDropDownOpen = false;
                            this.command.SelectedIndex = 1;
                            lastRecogVoice = "edit";
                            param1.IsEnabled = true;
                            param1.ItemsSource = EditList;
                            this.param1.IsDropDownOpen = true;
                           // param2.IsEnabled = true;
                           // param2.ItemsSource = ShapeList;
                            //this.param2.IsDropDownOpen = true;
                            speechRecognizer.UnloadGrammar(gcmd);
                            speechRecognizer.LoadGrammar(gedit);
                            //speechRecognizer.LoadGrammar(gshape);
                        }
                        break;
                    case "MERGE":
                        if (objManAud.Count > 1)        //if we have over 2 objects in objman
                        {
                            this.command.IsDropDownOpen = false;
                            this.command.SelectedIndex = 2;
                            lastRecogVoice = "merge";
                            param1.IsEnabled = true;
                            param1.ItemsSource = MergeList;
                            this.param1.IsDropDownOpen = true;
                            param3.IsEnabled = true;
                            param3.ItemsSource = SetList;
                            this.param3.IsDropDownOpen = true;
                            speechRecognizer.UnloadGrammar(gcmd);
                            speechRecognizer.LoadGrammar(gmerge);
                        }
                        break;
                    case "SCENE":
                        this.command.IsDropDownOpen = false;
                        this.command.SelectedIndex = 3;
                        lastRecogVoice = "scene";
                        param1.IsEnabled = true;
                        param1.ItemsSource = SceneList;
                        this.param1.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcmd);
                        speechRecognizer.LoadGrammar(gscene);
                        break;
                    case "UP":
                        this.param1.SelectedIndex = 0;
                        Coordpl.move_z_f();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "DOWN":
                        this.param1.SelectedIndex = 1;
                        Coordpl.move_z_b();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "LEFT":
                        this.param1.SelectedIndex = 2;
                        Coordpl.move_y_f();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "RIGHT":
                        this.param1.SelectedIndex = 3;
                        Coordpl.move_y_b();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "FORWARD":
                        this.param1.SelectedIndex = 4;
                        Coordpl.move_x_b();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "BACK":
                        this.param1.SelectedIndex = 5;
                        Coordpl.move_x_f();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "CLOCKWISE":
                        this.param1.SelectedIndex = 6;
                        Coordpl.rotate_clockwise();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "COUNTER":
                        this.param1.SelectedIndex = 7;
                        Coordpl.rotate_counterclockwise();
                        this.param1.IsDropDownOpen = true;
                        break;
                    case "HELP":
                        if (this.command.IsEnabled == true)
                        {
                            this.command.IsDropDownOpen = true; 
                        }
                        if (this.param1.IsEnabled == true)
                        {
                            this.param1.IsDropDownOpen = true;
                        }
                        if (this.param2.IsEnabled == true)
                        {
                            this.param2.IsDropDownOpen = true; 
                        }
                        if (this.param3.IsEnabled == true)
                        {
                            this.param3.IsDropDownOpen = true; 
                        }
                        break;
                    case "FINISHED":
                        is_numb_edit = true;
                        number.IsEnabled = true;
                        number.ItemsSource = NumberList;
                        number.IsDropDownOpen = true;
                        if (audio_numb.ToString() == "")
                        {
                            audio_numb += "0";
                        }
                        //if(audio_numb.Contains(".") == true)
                        //{
                        //    audio_numb += "0f";
                        //}
                        //else
                        //{
                        //    audio_numb += ".0f";
                        //}
                        stored_audio_number = audio_numb;
                        this.numberbox.Text = "";
                        audio_numb = "";
                        is_finished = true;
                        break;
                    case "DONE":
                        this.command.IsDropDownOpen = false;
                        this.param1.IsDropDownOpen = false;
                        this.param2.IsDropDownOpen = false;
                        this.param3.IsDropDownOpen = false;
                        if(audio_numb != "")
                        {
                            number.IsEnabled = true;
                            number.ItemsSource = NumberList;
                            number.IsDropDownOpen = true;
                            this.param2.SelectedIndex = 0;
                        }
                        this.is_Done = true;
                        if(audio_numb.Contains(".") == true)
                        {
                            audio_numb += "0f";
                        }
                        else
                        {
                            audio_numb += ".0f";
                        }
                        stored_audio_number = audio_numb;
                        this.numberbox.Text = "";
                        audio_numb = "";
                        //param3.SelectedIndex = 2;
                        break;
                    case "SET":
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gcmd);
                        this.numberbox.Text = "";
                        this.audio_numb = "";
                        this.param1.ItemsSource = "";
                        this.param2.ItemsSource = "";
                        this.param3.ItemsSource = "";
                        is_Creating = false;
                        is_Editing = false;
                        is_Rotating = false;
                        is_Scaling = false;
                        is_Translating = false;
                        is_Circle = false;
                        is_Square = false;
                        is_Cube = false;
                        is_Sphere = false;
                        is_Cylinder = false;
                        is_Gestures = false;
                        is_Select = false;
                        is_Bool = false;
                        said_bool = false;
                        is_union = false;
                        is_difference = false;
                        is_intersection = false;
                        is_numb_edit = false;
                        is_set_cancel = false;
                        is_finished = false;
                        this.command.IsEnabled = true;
                        this.command.IsDropDownOpen = true;
                        this.command.SelectedIndex = 0;
                        this.param1.IsDropDownOpen = false; 
                        this.param1.IsEnabled = false;
                        this.param2.IsDropDownOpen = false; 
                        this.param2.IsEnabled = false;
                        this.param3.IsDropDownOpen = false; 
                        this.param3.IsEnabled = false;
                        is_Set = true;
                        break;
                    case "CHOOSE":
                        param3.SelectedIndex = 1;
                        is_Select = true;
                        break;
                    case "CANCEL":
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gcmd);
                        this.numberbox.Text = "";
                        this.audio_numb = "";
                        this.param1.ItemsSource = "";
                        this.param2.ItemsSource = "";
                        this.param3.ItemsSource = "";
                        is_Creating = false;
                        is_Editing = false;
                        is_Rotating = false;
                        is_Scaling = false;
                        is_Translating = false;
                        is_Circle = false;
                        is_Square = false;
                        is_Cube = false;
                        is_Sphere = false;
                        is_Cylinder = false;
                        is_Gestures = false;
                        is_Select = false;
                        is_Bool = false;
                        said_bool = false;
                        is_union = false;
                        is_difference = false;
                        is_intersection = false;
                        is_numb_edit = false;
                        is_finished = false;
                        this.command.IsEnabled = true;
                        this.command.IsDropDownOpen = true;
                        this.param1.IsDropDownOpen = false; 
                        this.param1.IsEnabled = false;
                        this.param2.IsDropDownOpen = false; 
                        this.param2.IsEnabled = false;
                        this.param3.IsDropDownOpen = false; 
                        this.param3.IsEnabled = false;
                        is_set_cancel = true;
                        break;
                    case "GESTURE":
                        param3.IsEnabled = true;
                        param3.ItemsSource = SetList;
                        this.param3.IsDropDownOpen = true;
                        this.param2.SelectedIndex = 1;
                        is_Gestures = true;
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gset);
                        break;
                    case "EXACT":
                        is_numb_edit = true;
                        number.IsEnabled = true;
                        number.ItemsSource = NumberList;
                        number.IsDropDownOpen = true;
                        this.param1.IsDropDownOpen = false;
                        this.param2.SelectedIndex = 0;
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gnumber);
                        break;
                    case "CIRCLE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        is_Circle = true;
                        this.param1.SelectedIndex = 0;
                        break;
                    case "SQUARE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 1;
                        is_Square = true;
                        break;
                    case "POLYGON":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 2;
                        break;
                    case "SPHERE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 3;
                        is_Sphere = true;
                        break;
                    case "CUBE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 4;
                        is_Cube = true;
                        break;
                    case "CYLINDER":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 5;
                        //for now providing a quick way to render on the fly
                        is_Cylinder = true;
                        break;
                    case "POLYHEDRON":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        param2.ItemsSource = ShapeList;
                        this.param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadGrammar(gcreate);
                        speechRecognizer.LoadGrammar(gshape);
                        this.param1.SelectedIndex = 6;
                        //for now providing a quick way to render on the fly
                        ontheflylocal = true;
                        break;
                    case "BOOL":
                        is_Bool = true;
                        param2.IsEnabled = true;
                        param2.ItemsSource = MergeList;
                        param2.IsDropDownOpen = true;
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gmerge);
                        this.param1.SelectedIndex = 8;
                        break;
                    case "TRANSLATE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param2.ItemsSource = ShapeList;
                        is_Translating = true;
                        this.param1.SelectedIndex = 0;
                        lastRecogVoice = "translate";
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gshape);
                        
                        //for now providing a quick way to render on the fly
                        break;
                    case "ROTATE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param2.ItemsSource = ShapeList;
                        is_Rotating = true;
                        this.param1.SelectedIndex = 2;
                        lastRecogVoice = "rotate";
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gshape);
                        //for now providing a quick way to render on the fly
                        break;
                    case "SCALE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param2.ItemsSource = ShapeList;
                        is_Scaling = true;
                        this.param1.SelectedIndex = 3;
                        lastRecogVoice = "scale";
                        speechRecognizer.UnloadAllGrammars();
                        speechRecognizer.LoadGrammar(gshape);
                        //for now providing a quick way to render on the fly
                        break;
                    case "RESIZE":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param1.SelectedIndex = 4;
                        lastRecogVoice = "resize";
                        //for now providing a quick way to render on the fly
                        break;
                    case "MIRROR":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param1.SelectedIndex = 5;
                        lastRecogVoice = "mirror";
                        //for now providing a quick way to render on the fly
                        break;
                    case "MULTMATRIX":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param1.SelectedIndex = 6;
                        lastRecogVoice = "multmatrix";
                        //for now providing a quick way to render on the fly
                        break;
                    case "COLOR":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param1.SelectedIndex = 7;
                        lastRecogVoice = "color";
                        //for now providing a quick way to render on the fly
                        break;
                    case "HULL":         //tells brians code to start getting values from the shape we just "set"
                        param2.IsEnabled = true;
                        this.param2.IsDropDownOpen = true;
                        this.param1.SelectedIndex = 8;
                        lastRecogVoice = "hull";
                        //for now providing a quick way to render on the fly
                        break;
                    case "UNION":         //tells brians code to start getting values from the shape we just "set"
                        if (is_Bool == true)
                        {
                            this.param2.SelectedIndex = 0;
                            speechRecognizer.UnloadAllGrammars();
                            speechRecognizer.LoadGrammar(gset);
                            param3.IsEnabled = true;
                            this.param3.ItemsSource = SetList;
                            this.param3.IsDropDownOpen = true;
                            is_union = true;
                        }
                        else
                        {
                            param2.IsEnabled = true;
                            this.param2.IsDropDownOpen = true;
                            this.param1.SelectedIndex = 0;
                            lastRecogVoice = "union";
                        }
                        //for now providing a quick way to render on the fly
                        break;
                    case "DIFFERENCE":         //tells brians code to start getting values from the shape we just "set"
                        if (is_Bool == true)
                        {
                            this.param2.SelectedIndex = 1;
                            speechRecognizer.UnloadAllGrammars();
                            speechRecognizer.LoadGrammar(gset);
                            param3.IsEnabled = true;
                            this.param3.ItemsSource = SetList;
                            this.param3.IsDropDownOpen = true;
                            is_difference = true;
                        }
                        else
                        {
                            speechRecognizer.UnloadAllGrammars();
                            speechRecognizer.LoadGrammar(gset);
                            param2.IsEnabled = true;
                            this.param2.IsDropDownOpen = true;
                            this.param1.SelectedIndex = 1;
                            lastRecogVoice = "difference";
                        }
                        //for now providing a quick way to render on the fly
                        break;
                    case "INTERSECTION":         //tells brians code to start getting values from the shape we just "set"
                        if (is_Bool == true)
                        {
                            this.param2.SelectedIndex = 2;
                            speechRecognizer.UnloadAllGrammars();
                            speechRecognizer.LoadGrammar(gset);
                            is_intersection = true;
                            param3.IsEnabled = true;
                            this.param3.ItemsSource = SetList;
                            this.param3.IsDropDownOpen = true;
                        }
                        else
                        {
                            param2.IsEnabled = true;
                            this.param2.IsDropDownOpen = true;
                            this.param1.SelectedIndex = 2;
                            lastRecogVoice = "intersection";
                        }
                        //for now providing a quick way to render on the fly
                        break;
                    case "ZERO":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "zero";
                        number.IsDropDownOpen = true;
                        audio_numb += "0";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "POINT":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "point";
                        number.IsDropDownOpen = true;
                        //text1.Text = "point";
                        audio_numb += ".";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "ONE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "one";
                        number.IsDropDownOpen = true;
                        //text1.Text = "one";
                        audio_numb += "1";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "TWO":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "two";
                        number.IsDropDownOpen = true;
                        //text1.Text = "two"; 
                        audio_numb += "2";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "THREE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "three";
                        number.IsDropDownOpen = true;
                        //text1.Text = "three";
                        audio_numb += "3";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "FOUR":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "four";
                        number.IsDropDownOpen = true;
                        //text1.Text = "four";
                        audio_numb += "4";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "FIVE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "five";
                        number.IsDropDownOpen = true;
                        //text1.Text = "five";
                        audio_numb += "5";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "SIX":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "six";
                        number.IsDropDownOpen = true;
                        //text1.Text = "six";
                        audio_numb += "6";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "SEVEN":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "seven";
                        number.IsDropDownOpen = true;
                        //text1.Text = "seven";
                        audio_numb += "7";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "EIGHT":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "eight";
                        number.IsDropDownOpen = true;
                        //text1.Text = "eight";
                        audio_numb += "8";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "NINE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "nine";
                        number.IsDropDownOpen = true;
                        //text1.Text = "nine";
                        audio_numb += "9";
                        numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
        
                    /*case "CANCEL":
                        if (lastRecogVoice == "zero" || lastRecogVoice == "one" || lastRecogVoice == "two" || lastRecogVoice == "three" || lastRecogVoice == "four" || lastRecogVoice == "five" || lastRecogVoice == "six" || lastRecogVoice == "seven" || lastRecogVoice == "eight" || lastRecogVoice == "nine" || lastRecogVoice == "point")
                        {
                            audio_numb = audio_numb.Remove(audio_numb.Length - 1);
                            //numberbox.Text = audio_numb;
                            lastRecogVoice = "";
                        }
                        else if (lastRecogVoice == "translate")
                        {
                            //
                        }
                        else
                        {
                            lastRecogShape = "";
                            lastRecogVoice = "";
                            ontheflylocal = false;
                        }
                            //text1.Text = "cancel";
                        break;
                    case "TRANSLATE":
                        this.command.ItemsSource = EditList;
                        lastRecogVoice = "translate";
                        if (heard == 1)
                        {
                            //text1.Text = "translate";
                            objManAud.currentSelected.translate(InitGestureDetector.right.X, InitGestureDetector.right.Y, 1);
                        }
                        break;
                    case "SQUARE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "square";
                        //text1.Text = "square";
                        lastRecogShape = "square";
                        //for now providing a quick way to render on the fly
                        ontheflylocal = true;
                        //lastRecogVoice = DateTime.Now;
                        break;
                    /*case "ZERO":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "zero";
                        audio_numb += "0";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "POINT":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "point";
                        //text1.Text = "point";
                        audio_numb += ".";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "ONE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "one";
                        //text1.Text = "one";
                        audio_numb += "1";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "TWO":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "two";
                        //text1.Text = "two"; 
                        audio_numb += "2";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "THREE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "three";
                        //text1.Text = "three";
                        audio_numb += "3";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "FOUR":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "four";
                        //text1.Text = "four";
                        audio_numb += "4";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "FIVE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "five";
                        //text1.Text = "five";
                        audio_numb += "5";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "SIX":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "six";
                        //text1.Text = "six";
                        audio_numb += "6";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "SEVEN":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "seven";
                        //text1.Text = "seven";
                        audio_numb += "7";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "EIGHT":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "eight";
                        //text1.Text = "eight";
                        audio_numb += "8";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "NINE":         //tells brians code to start getting values from the shape we just "set"
                        lastRecogVoice = "nine";
                        //text1.Text = "nine";
                        audio_numb += "9";
                        //numberbox.Text = audio_numb;
                        //for now providing a quick way to render on the fly
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "CIRCLE":         //tells brians code to start getting values from the shape we just "set"
                        param1.IsEnabled = false;
                        this.command.ItemsSource = CreateList;
                        //text1.Text = "circle";
                        lastRecogShape = "circle";
                        //lastRecogVoice = DateTime.Now;
                        break;
                    case "CHOOSE":                      //case is for selecting object
                        lastRecogVoice = "choose";
                        //text1.Text = "choose";
                        //lastRecogVoice = DateTime.Now;
                        //text2.Text = "";
                        //text3.Text = "Microsoft";
                        break;
                    case "CUT":                         //this case is for cutting an object into another
                        this.command.ItemsSource = EditList;
                        lastRecogVoice = "cut";
                        //text1.Text = "cut";
                        //lastRecogVoice = DateTime.Now;
                        //We need to cut
                        scadObj cutObj = new scadObj();
                        cutObj.BooleanCmd = "difference()";

                        if (selectedOne.GetType() == typeof(scadObj) && selectedTwo.GetType() == typeof(scadObj))
                        {
                            cutObj.threeDcmd = selectedOne.toScad() + selectedTwo.toScad();
                        }
                        else if ((selectedOne.GetType() == typeof(Square) || selectedOne.GetType() == typeof(Circle)) && selectedTwo.GetType() == typeof(scadObj))
                        {

                            cutObj.twoDcmd = selectedOne.toScad();
                            cutObj.threeDcmd = selectedTwo.toScad();
                        }
                        else if ((selectedTwo.GetType() == typeof(Square) || selectedTwo.GetType() == typeof(Circle)) && selectedOne.GetType() == typeof(scadObj))
                        {
                            cutObj.twoDcmd = selectedTwo.toScad();
                            cutObj.threeDcmd = selectedOne.toScad();
                        }
                        else
                        {
                            cutObj.twoDcmd = selectedOne.toScad() + selectedTwo.toScad();

                        }
                        break;
                    case "SET":
                        //add a new object
                        // objectViewer.Items.Add("NewObj");
                        this.command.ItemsSource = EditList;
                        //text1.Text = "set";
                        lastRecogVoice = "set";
                        if (lastRecogShape == null)
                            break;
                        else
                        {
                            ontheflylocal = false;
                            if (lastRecogShape == "square")
                            {
                                Square testSquare = new Square(InitGestureDetector.Origin);
                                testSquare.endPoint(InitGestureDetector.left, InitGestureDetector.right);
                                objManAud.addObject(testSquare); //add it
                                objManAud.updateViewer(AudObjectViewer);
                                testobjectpos(objManAud);
                                ontheflylocal = false;
                                writeToScad();

                                //string testme = testSquare.Height.ToString() + " and " + testSquare.Length.ToString();
                                //MessageBox.Show(testme);
                            }
                            else if (lastRecogShape == "circle")
                            {
                                Circle testCircle = new Circle(InitGestureDetector.Origin);
                                testCircle.endPoint(InitGestureDetector.right);
                                objManAud.addObject(testCircle);//add it
                                objManAud.updateViewer(AudObjectViewer);
                                testobjectpos(objManAud);
                                ontheflylocal = false;
                                writeToScad();
                            }
                            else //no shape
                            {
                                MessageBox.Show("No Valid shape chosen");
                            }
                        }
                        break;
                    case "NEXT":
                        lastRecogVoice = "next";
                        if (AudObjectViewer.SelectedIndex != AudObjectViewer.Items.Count - 1)
                            AudObjectViewer.SelectedIndex = AudObjectViewer.SelectedIndex + 1;
                        else
                            AudObjectViewer.SelectedIndex = 0;
                        break;
                    case "PREVIOUS":
                        lastRecogVoice = "previous";
                        if (AudObjectViewer.SelectedIndex != 0)
                            AudObjectViewer.SelectedIndex = AudObjectViewer.SelectedIndex - 1;
                        else
                            AudObjectViewer.SelectedIndex = AudObjectViewer.Items.Count - 1;
                        break;
                    case "MOVE":
                        if ((Math.Abs((double)(InitGestureDetector.left.Y - InitGestureDetector.right.Y)) <= 100))
                        {
                            ontheflylocal = true;
                        }
                        break;
                    /*
                    for (int gr = 0; gr < objMan.Count; gr++ )
                    {
                        if (Math.Abs((double)(InitGestureDetector.right.X - objMan.Objects[gr].Origin.X)) <= 20 &&
                            Math.Abs((double)(InitGestureDetector.right.Y - objMan.Objects[gr].Origin.Y)) <= 20 &&
                            Math.Abs((double)(InitGestureDetector.right.Z - objMan.Objects[gr].Origin.Z)) <= 20)
                        {
                            //grabenabled = true;
                            //grabname = objMan.Objects[gr].Name.ToString();
                            objMan.Objects[gr].updateOrigin(InitGestureDetector.left);
                            //break;
                        }  
                    }
                        //some grab stuff
                        //look through object man to find the closest point to your current hand
                    break;
                case "test":
                        
                    break;

                default:
                    break;
            }
        }   
        //} 
        else
        {
            //double time = DateTime.Now.Subtract(lastRecogVoice).TotalMilliseconds;
            //ToString(time);
            double time = (windowForVoice - DateTime.Now.Subtract(lastRecogVoice).Seconds) - 4995;
            string timeleft = System.Convert.ToString(time);
            text1.Text = timeleft + " second wait";
        }   

            
    }
        }
        else
        {
            //double time = DateTime.Now.Subtract(lastRecogVoice).TotalMilliseconds;
            //ToString(time);
            double time = (windowForVoice - DateTime.Now.Subtract(lastRecogVoice).Seconds) - 4995;
            string timeleft = System.Convert.ToString(time);
            text1.Text = timeleft + " second wait";
        } 
    }
    //end of audio code */
                }
            }
        }
    }
}
